using UnityEngine;
using UnityEngine.InputSystem;

/// <summary>
/// 玩家输入
/// </summary>
public class PlayerInput : MonoBehaviour
{
    public Vector2 MoveInput { get; private set; }// 用于存储移动输入的向量
    public Vector2 LookInput { get; private set; }// 用于存储视角输入的向量
    private InputActions _input;

    private void OnEnable()
    {
        _input = new InputActions();
        _input.Player.Enable();

        _input.Player.Move.performed += SetMove;
        _input.Player.Move.canceled += SetMove;
        _input.Player.Look.performed += SetLook;
        _input.Player.Look.canceled += SetLook;
    }

    private void OnDisable()
    {
        _input.Player.Move.performed -= SetMove;
        _input.Player.Move.canceled -= SetMove;
        _input.Player.Look.performed -= SetLook;
        _input.Player.Look.canceled -= SetLook;
        _input.Player.Disable();  
    }

    
    private void SetMove(InputAction.CallbackContext context)
    {
        MoveInput = context.ReadValue<Vector2>();
    }

    private void SetLook(InputAction.CallbackContext context)
    {
        LookInput = context.ReadValue<Vector2>();
    }
}
